import axios, {AxiosResponse, InternalAxiosRequestConfig} from "axios";
import {message} from "ant-design-vue";
import {generateRandomString} from "@/utils";

const baseConfig = {
    baseURL: '/api', timeout: 60 * 1000
}
export const http = axios.create(baseConfig)
http.interceptors.request.use((config: InternalAxiosRequestConfig) => {
    config.headers['Authorization'] = `oAuth ${generateRandomString(256)}`
    return config
}, (error) => {
    return Promise.reject(error)
})
http.interceptors.response.use((res: AxiosResponse) => {
    return res.data
}, (err) => {
    message.error(err.message)
    return Promise.reject(err)
})
